import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import java.awt.*;

final class FileTree extends JPanel{
  private final Doer frame;
  private final DefaultMutableTreeNode root=new DefaultMutableTreeNode("File");
  private final JTree tree=new JTree(root);
  FileTree(final Doer frame){
    this.frame=frame;

    add(tree);
    tree.setEditable(false);
    setBackground(Color.WHITE);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    setLayout(new FlowLayout(FlowLayout.LEFT));
    
    final JTabbedPane tab=frame.getTab();
    
    tree.addTreeSelectionListener(new TreeSelectionListener(){
      public void valueChanged(TreeSelectionEvent e){
	DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
	if (selectionNode.isLeaf()) {
          int leaf=root.getIndex(selectionNode);
	  if(leaf>-1)frame.getTab().setSelectedIndex(leaf);
	}
      }
    });
  }
  public JTree getTree(){
    return tree;
  }
  public DefaultMutableTreeNode getRoot(){
    return root;
  }
}
